﻿/**
 * 宏
 *
 * @file LoggerPrintf.h
 * @author Song
 * @date 2011-9-18
 *
 */

#pragma once

namespace log4lite {
	extern Logger logger;
}

#ifdef _MSC_VER
#	pragma warning (disable : 4127) // 条件表达式是常量
#endif // _MSC_VER

/// @addtogroup PRINTF系列宏
/// 
/// @{

#define log4lite_MACRO_BODY(logItem, logCatagory)    \
	do {                                                      \
	if( (log4lite::logger).isEnabledFor(log4lite::logCatagory) ) {    \
	log4lite::tostringstream log4lite_buf;               \
	log4lite_buf << logItem;                           \
	(log4lite::logger).forcedLog(log4lite::logCatagory,           \
	log4lite_buf.str(), __FILE__, __LINE__);           \
	}													  \
	} while (0)



#define log4lite_MACRO_STR_BODY(logItem, logCatagory)     \
	do {                                                           \
	if((log4lite::logger).isEnabledFor(log4lite::logCatagory)) {        \
	(log4lite::logger).forcedLog(log4lite::logCatagory, logItem, __FILE__, __LINE__);   \
	}                                                               \
	} while(0 == 1)


#if !defined(log4lite_DISABLE_TRACE)
#	define PRINTF_TRACE(logItem)		log4lite_MACRO_BODY(logItem, TRACE_LOG_CATAGORY)
#	define PRINTF_TRACE_PTR(logItem)	log4lite_MACRO_STR_BODY(logItem, TRACE_LOG_CATAGORY)
#else
#	define PRINTF_TRACE(logItem)		do { } while (0)
#	define PRINTF_TRACE_PTR(logItem)	do { } while (0)
#endif

#ifndef log4lite_DISABLE_WARN
#	define PRINTF_WARN(logItem)		log4lite_MACRO_BODY(logItem, WARN_LOG_CATAGORY)
#	define PRINTF_WARN_PTR(logItem)	log4lite_MACRO_STR_BODY(logItem, WARN_LOG_CATAGORY)
#else
#	define PRINTF_WARN(logItem)		do { } while (0)
#	define PRINTF_WARN_PTR(logItem)	do { } while (0)
#endif

#if !defined(log4lite_DISABLE_FATAL)
#	define PRINTF_FATAL(logItem)		log4lite_MACRO_BODY(logItem, FATAL_LOG_CATAGORY)
#	define PRINTF_FATAL_PTR(logItem)	log4lite_MACRO_STR_BODY(logItem, FATAL_LOG_CATAGORY)
#else
#	define PRINTF_FATAL(logItem)		do { } while (0)
#	define PRINTF_FATAL_PTR(logItem)	do { } while (0)
#endif

#if !defined(log4lite_DISABLE_ERROR)
#	define PRINTF_ERROR(logItem)		log4lite_MACRO_BODY(logItem, ERROR_LOG_CATAGORY)
#	define PRINTF_ERROR_PTR(logItem)	log4lite_MACRO_STR_BODY(logItem, ERROR_LOG_CATAGORY)
#else
#	define PRINTF_ERROR(logItem)		do { } while (0)
#	define PRINTF_ERROR_PTR(logItem)	do { } while (0)
#endif

#if !defined(log4lite_DISABLE_INFO)
#	define PRINTF_INFO(logItem)		log4lite_MACRO_BODY(logItem, INFO_LOG_CATAGORY)
#	define PRINTF_INFO_PTR(logItem)	log4lite_MACRO_STR_BODY(logItem, INFO_LOG_CATAGORY)
#else
#	define PRINTF_INFO(logItem)		do { } while (0)
#	define PRINTF_INFO_PTR(logItem)	do { } while (0)
#endif

#if !defined(log4lite_DISABLE_DEBUG)
#	define PRINTF_DEBUG(logItem)		log4lite_MACRO_BODY(logItem, DEBUG_LOG_CATAGORY)
#	define PRINTF_DEBUG_PTR(logItem)	log4lite_MACRO_STR_BODY(logItem, DEBUG_LOG_CATAGORY)
#else
#	define PRINTF_DEBUG(logItem)		do { } while (0)
#	define PRINTF_DEBUG_PTR(logItem)	do { } while (0)
#endif

/// @}
